package com.icetech.eom.service.impl.tx;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.icetech.eom.dao.tx.UDevDao;
import com.icetech.eom.domain.tx.UDev;
import com.icetech.eom.domain.tx.dto.UserDeviceDto;
import com.icetech.eom.service.tx.IUDevService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangzw
 * @since 2018-11-12
 */
@Service
public class UDevServiceImpl extends ServiceImpl<UDevDao, UDev> implements IUDevService {
    @Autowired
    private UDevDao uDevDao;

    @Override
    public List<UserDeviceDto> selectBindUsers(Long deviceId) {
        List<UserDeviceDto> userDeviceDtos = uDevDao.selectBindUsers(deviceId);
        return userDeviceDtos;
    }

    @Override
    public boolean cancelBind(Long deviceId,Long userId) {
        UDev uDev = uDevDao.selectByUserIdAndDevId(deviceId, userId);
        if (Objects.isNull(uDev))return Boolean.TRUE;
        HashMap<String, Object> params = Maps.newHashMap();
        params.put("dev_id",deviceId);
        params.put("user_id",userId);
        int i = uDevDao.deleteByMap(params);
        return i>0?Boolean.TRUE:Boolean.FALSE;
    }

    @Override
    public UDev selectByUserIdAndDevId(Long devId, Long userid) {
        return uDevDao.selectByUserIdAndDevId(devId,userid);
    }

    @Override
    public List<UserDeviceDto> selectBindRegister(Long deviceId) {
        return uDevDao.selectBindRegister(deviceId);
    }
}
